﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestInst
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            ib1 = new TestInst.view.InputBox();
            ib1.InputBoxValueChanged += new TestInst.view.InputBox.TextBoxChangedHandle(ib_InputBoxValueChanged);
            ib2 = new TestInst.view.TestInherited();
            ib2.InputBoxValueChanged += new TestInst.view.InputBox.TextBoxChangedHandle(ib_InputBoxValueChanged);
            tps = new TestInst.view.TabPages();
            lsp = new TestInst.view.ListPage();
            preControls = new LinkedList<string>();
        }

        private void RefreshForm(Control userControl)
        {
            if (preControls.Count > 0)
            {
                foreach (string c in preControls)
                {
                    this.Controls.RemoveByKey(c);
                }              
            }
            preControls.AddLast(userControl.Name);
            this.Controls.Add(userControl);
        }

        private void ib_InputBoxValueChanged(object sender, TestInst.view.InputBox.TextChangeEventArgs e)
        {
            MessageBox.Show("当前控件的值为:" + e.Message);
        }

        private void case1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            RefreshForm(ib1);
        }

        private void case2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            RefreshForm(ib2);
        }

        private TestInst.view.InputBox ib1;
        private TestInst.view.TestInherited ib2;
        private TestInst.view.TabPages tps;
        private TestInst.view.ListPage lsp;
        private LinkedList<string> preControls;

        private void case3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RefreshForm(tps);
        }

        private void case4ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RefreshForm(lsp);
        }

    }
}
